#!/bin/sh mongo数据按天备份,减少数据重复备份
tables="expendUse testItem"
start=`date  -d 'yesterday' +%Y-%m-%d`
end=`date  -d 'today' +%Y-%m-%d`
start='2018-12-01'
p='/root/mongobak'
echo start $start end $end
query="{crtTime:{\$gte:'$start 00:00:00',\$lt:'$end 00:00:00'}}"
echo $query
for t in $tables
do
echo table $t
c=`mongo 192.168.1.164/iot-tenant --eval "db.$t.count($query)"|tail -n 1`
echo count $c
if [ "$c" -ne "0" ]
then
echo dump data
mongoexport -h 192.168.1.164 -d iot-tenant -c $t -q "$query" -o $p/$t$start
fi
done